package com.elink.enginerring.category.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.elink.enginerring.category.dao.DetailCategoryMapper;
import com.elink.enginerring.category.dao.SecondaryCategoryMapper;
import com.elink.enginerring.category.dao.TopCategoryMapper;
import com.elink.enginerring.category.entity.DetailCategory;
import com.elink.enginerring.category.entity.SecondaryCategory;
import com.elink.enginerring.category.entity.TopCategory;

@Service
public class CategoryService implements ICategoryService {
	@Autowired
	private TopCategoryMapper topCategoryMapper;
	@Autowired
	private SecondaryCategoryMapper secondaryCategoryMapper;
	@Autowired
	private DetailCategoryMapper detailCategoryMapper;

	@Override
	public List<TopCategory> getTopCategory() {
		return topCategoryMapper.selectList();
	}
	
	@Override
	public List<TopCategory> getTopCategoryOfDatabase() {
		return topCategoryMapper.selectListOfDatabase();
	}
	
	@Override
	public List<TopCategory> getTopCategoryOfCert() {
		return topCategoryMapper.selectTopCategoryOfCert();
	}
	@Override
	public List<TopCategory> getTopCategoryOfBuild() {
		return topCategoryMapper.selectTopCategoryOfBuild();
	}

	@Override
	public List<TopCategory> getTopCategoryOfPlan() {
		return topCategoryMapper.selectTopCategoryOfCert();
	}

	
	@Override
	public List<TopCategory> getTopCategoryOfLibrary() {
		return topCategoryMapper.selectListOfLibrary();
	}
	@Override
	public List<TopCategory> getTopCategoryOfNews() {
		return topCategoryMapper.selectListOfNews();
	}
	@Override
	public List<TopCategory> getTopCategoryOfVideo() {
		return topCategoryMapper.selectListOfVideo();
	}
	@Override
	public List<TopCategory> getTopCategoryOfSkill() {
		return topCategoryMapper.selectListOfSkill();
	}
	@Override
	public List<SecondaryCategory> getSecondaryCategory(int tcId) {
		return secondaryCategoryMapper.selectListByTcId(tcId);
	}

	@Override
	public List<DetailCategory> getDetailCategory(int scId,int dcTypeId) {
		return detailCategoryMapper.selectListByScId(scId,dcTypeId);
	}

	@Override
	public void addTop(TopCategory tc) {
		topCategoryMapper.insertSelective(tc);
	}

	@Override
	public void addSecond(SecondaryCategory sc) {
		secondaryCategoryMapper.insertSelective(sc);
		
	}

	@Override
	public void addDetail(DetailCategory dc) {
		detailCategoryMapper.insertSelective(dc);
	}

	@Override
	public void modifyTop(TopCategory tc) {
		topCategoryMapper.updateByPrimaryKeySelective(tc);
	}

	@Override
	public void modifySecond(SecondaryCategory sc) {
		secondaryCategoryMapper.updateByPrimaryKeySelective(sc);
	}

	@Override
	public void modifyDetail(DetailCategory dc) {
		detailCategoryMapper.updateByPrimaryKeySelective(dc);
	}

	@Override
	public void del(int id, int type) {
		if(type == 1){
			topCategoryMapper.deleteByPrimaryKey(id);
		}else if(type == 2){
			secondaryCategoryMapper.deleteByPrimaryKey(id);
		}else if(type == 3){
			detailCategoryMapper.deleteByPrimaryKey(id);
		}
	}
}
